unit dmda_Stock;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, dmModule, DB, FR_DSet, FR_DBSet, ADODB;

type
  Tdtmda_Stock = class(TdtmModule)
    adsStockType: TADODataSet;
    adsMasterEditHasUse2: TBooleanField;
    adsMasterEditHasStop2: TBooleanField;
    adsMasterEditRemark2: TStringField;
    adsMasterEditStopDate: TDateTimeField;
    adsMasterEditStoper2: TStringField;
    adsMasterEditStopMemo2: TStringField;
    adsMasterEditWriter2: TStringField;
    adsMasterEditWriteTime2: TDateTimeField;
    adsMasterEditModifyTime2: TDateTimeField;
    adsMasterEditModifier2: TStringField;
    adsMasterEditHasCheck2: TBooleanField;
    adsMasterEditCheckTime2: TDateTimeField;
    adsMasterEditChecker2: TStringField;
    adsMasterEditHasSysDefine: TBooleanField;
    adsMasterEditHasDefault: TBooleanField;
    adsMasterHasStop: TBooleanField;
    adsMasterHasUse: TBooleanField;
    adsMasterHasSysDefine: TBooleanField;
    adsMasterHasDefault: TBooleanField;
    adsMasterStoper: TStringField;
    adsMasterStopDate: TDateTimeField;
    adsMasterStopMemo: TStringField;
    adsMasterHasCheck: TBooleanField;
    adsMasterChecker: TStringField;
    adsMasterCheckTime: TDateTimeField;
    adsMasterWriter: TStringField;
    adsMasterWriteTime: TDateTimeField;
    adsMasterModifier: TStringField;
    adsMasterModifyTime: TDateTimeField;
    adsMasterRemark: TStringField;
    adsStockTypeID: TStringField;
    adsStockTypeCode: TStringField;
    adsStockTypeName: TStringField;
    adsMasterEditDeptID: TStringField;
    adsUserCompany: TADODataSet;
    adsMasterEditStockID: TStringField;
    adsMasterEditStockCode: TStringField;
    adsMasterEditStockName: TStringField;
    adsMasterEditStockType: TWordField;
    adsMasterEditres_StockTypeName: TStringField;
    adsMasterStockID: TStringField;
    adsMasterStockCode: TStringField;
    adsMasterStockName: TStringField;
    adsMasterStockType: TWordField;
    adsMasterres_StockTypeName: TStringField;
    adsMasterDeptID: TStringField;
    adsDepartment: TADODataSet;
    adsMasterEditres_DeptName: TStringField;
    adsMasterEditHasBarCode: TBooleanField;
    adsMasterHasBarCode: TBooleanField;
    adsMasterEditHelperCode: TStringField;
    adsMasterEditExportType: TStringField;
    adsMasterEditHasClearStock: TBooleanField;
    adsMasterEditSupplyID: TStringField;
    res_Supply: TADODataSet;
    adsMasterEditres_SupplyName: TStringField;
    adsMasterEditStockRuleID: TStringField;
    procedure adsMasterEditNewRecord(DataSet: TDataSet);
    procedure adsMasterEditStockNameChange(Sender: TField);
  private
    { Private declarations }
  protected
    procedure ModuleInit;override;
    procedure OpenEditDataSet; override;
  public
    { Public declarations }
    FStockType: string;
  end;

var
  dtmda_Stock: Tdtmda_Stock;

implementation

uses uGlobal,uMsgBox,uShare, uConst, uSQL, dmConnect;

{$R *.dfm}

{ Tdtmda_Stock }

procedure Tdtmda_Stock.ModuleInit;
begin
  FUniqueTable := 'da_Stock';
  inherited;
end;  

procedure Tdtmda_Stock.OpenEditDataSet;
begin
  FMasterEditTable := 'da_Stock';
  FMasterKeyField := 'StockID';
  inherited;
end;

procedure Tdtmda_Stock.adsMasterEditNewRecord(DataSet: TDataSet);
begin
  inherited;
  if (adsMasterEdit.State in [dsInsert, dsEdit]) and (FStockType<>'') then
  begin
    adsMasterEdit.FieldByName('StockType').ReadOnly := False;
    adsMasterEdit.FieldByName('StockType').AsString := FStockType;
  end;
end;

procedure Tdtmda_Stock.adsMasterEditStockNameChange(Sender: TField);
begin
  inherited;
  if adsMasterEdit.State in [dsInsert, dsEdit] then
  begin
    adsMasterEdit.FieldByName('HelperCode').ReadOnly := False;
    adsMasterEdit.FieldByName('HelperCode').AsString :=
      GetHzPy(adsMasterEdit.FieldByName('StockName').AsString);
  end;
end;

end.

